﻿using Microsoft.AspNetCore.Mvc;
using MultWebApi.Models;
using MultWebApi.SalesWebApi.Auth;
using System.Security.Claims;

namespace MultWebApi.SalesWebApi.Controllers
{
    [ApiController]
    [Route("Sale/")]
    [UserCheckControllerFilter]
    public class SaleController : Controller
    {
        [HttpPost("NewOrder")]
        [UserCheck(SystemFlag =1, Action="Inner")]
        public IActionResult NewOrder()
        {
            var rst = new DataResult();
            rst.ErrorCode = SysErrorCode.KSuccess;
            rst.Data = new { Id = "SE20250417001", Name = "SalesOrder", CreateDate = DateTime.Today.ToLongDateString() };
            rst.Message = SysErrorCode.GetErrorMessge(rst.ErrorCode);
            return new JsonResult(rst);
        }

        [UserCheck(SystemFlag = 1, Action = "Guest")]
        [HttpGet("GetUserName")]
        public IActionResult GetUserName()
        {
            string name = HttpContext.User.Claims.FirstOrDefault(p => p.Type == ClaimTypes.Name)?.Value;
            var rst = new DataResult();
            rst.ErrorCode = SysErrorCode.KSuccess;
            rst.Data = new { Name = name };
            rst.Message = SysErrorCode.GetErrorMessge(rst.ErrorCode);
            return new JsonResult(rst);
        }

        [HttpPost("NewComplaint")]
        [UserCheck(SystemFlag = 1, Action = "Guest")]
        public IActionResult NewComplaint(string? content)
        {
            var rst = new DataResult();
            rst.ErrorCode = SysErrorCode.KSuccess;
            rst.Data = new { Id = "CP20250417001", Name = "GuestComplain",Content=content??"(None)", CreateDate = DateTime.Today.ToLongDateString() };
            rst.Message = SysErrorCode.GetErrorMessge(rst.ErrorCode);
            return new JsonResult(rst);
        }
    }
}
